#!/usr/bin/env python

import os,cPickle

try:
    with open('/tmp/monitor-daemon.txt','r') as f:
        alldata = cPickle.load(f)
        other = cPickle.load(f)
except:
    print '%s get params error,exit run: %s' % (__file__,__file__)
    sys.exit()
nowtime = int(other['starttime'])
for i in alldata:
    for c in ['check_cpu_load','check_mem_usage','check_total_procs','check_ping']:
        os.system('bash /cihi/web/web/rrdtool/rrdtoolupdate.sh %s %s %s %s' % (i,c,nowtime,alldata[i][c]))
        try:
            rx = eval(alldata[i]['check_traffic'])['rx']
            tx = eval(alldata[i]['check_traffic'])['tx']
        except:
            rx = 'Unknow'
            tx = 'Unknow'
        os.system('bash /cihi/web/web/rrdtool/rrdtoolupdate.sh %s %s %s %s:%s' % (i,'check_traffic',nowtime,rx,tx))
